{
 "cells": [
  {
   "cell_type": "code",
   "id": "fd7a6aaf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:18.912864Z",
     "start_time": "2025-05-26T06:32:18.876665Z"
    }
   },
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import pypandoc\n",
    "import os\n",
    "import pathlib\n",
    "import fuzzywuzzy\n",
    "from fuzzywuzzy import fuzz\n",
    "import shutil\n",
    "\n",
    "sources = set(os.listdir(\"md\"))\n",
    "# sources"
   ],
   "outputs": [],
   "execution_count": 1
  },
  {
   "cell_type": "code",
   "id": "a6deda9e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.046114Z",
     "start_time": "2025-05-26T06:32:19.041691Z"
    }
   },
   "source": [
    "src_path = pathlib.Path(\"..\") / \"..\" / \"..\" / \"..\" / \"..\" / \"..\" \\\n",
    "           / \"src\" / \"main\" / \"java\" / \\\n",
    "           \"cn\" / \"edu\" / \"usst\" / \"cs\" / \"campusAid\"\n",
    "print(src_path.exists())\n",
    "package_names = [i for i in os.listdir(src_path) if not '.java' in i]\n",
    "print(package_names)\n",
    "print(src_path.resolve().absolute())\n",
    "# print(pathlib.Path(\".\").absolute())"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "['config', 'controller', 'dto', 'handler', 'interceptor', 'mapper', 'model', 'service', 'util']\n",
      "C:\\Users\\jerry\\IdeaProjects\\campusAid\\src\\main\\java\\cn\\edu\\usst\\cs\\campusAid\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "id": "a47bfcf0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.063958Z",
     "start_time": "2025-05-26T06:32:19.061109Z"
    }
   },
   "source": [
    "packages = {}"
   ],
   "outputs": [],
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "id": "6e695c02",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.079683Z",
     "start_time": "2025-05-26T06:32:19.075805Z"
    }
   },
   "source": [
    "def get_package_name(class_name):\n",
    "    for package_name in package_names:\n",
    "        package = src_path / package_name\n",
    "        max_rate = 0\n",
    "        for file in package.rglob(\"*.java\"):\n",
    "            rate = fuzz.ratio(class_name, file.name.replace(\".java\", \"\"))\n",
    "            if rate > max_rate:\n",
    "                max_rate = rate\n",
    "            if max_rate > 80:\n",
    "                return package_name\n",
    "        print(f\"Class name {class_name} does not match with {package.name}, rate: {max_rate}\")\n",
    "    raise FileNotFoundError(f\"Class {class_name} not found in any package.\")"
   ],
   "outputs": [],
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "id": "4ff32712",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.095246Z",
     "start_time": "2025-05-26T06:32:19.089611Z"
    }
   },
   "source": [
    "candidates = [filename.split(\".\")[0] for filename in sources if filename.endswith(\".md\")]\n",
    "len(candidates)"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "108"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "id": "41c5aa4d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.334925Z",
     "start_time": "2025-05-26T06:32:19.105781Z"
    }
   },
   "source": [
    "for class_name in candidates:\n",
    "    if class_name == \"CampusAidApplication\":\n",
    "        continue\n",
    "    if \"impl\" in class_name.lower():\n",
    "        continue\n",
    "    try:\n",
    "        package = get_package_name(class_name)\n",
    "        if 'sessionkeys' in class_name.lower():\n",
    "            package = 'dto'\n",
    "    except:\n",
    "        print(f\"Class {class_name} not found in any package.\")\n",
    "        continue\n",
    "    if package in packages.keys():\n",
    "        packages[package].add(class_name)\n",
    "    else:\n",
    "        packages[package] = {class_name}\n",
    "# packages"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Class name ErrandController does not match with config, rate: 35\n",
      "Class name ForumInterceptorTemplated does not match with config, rate: 46\n",
      "Class name ForumInterceptorTemplated does not match with controller, rate: 55\n",
      "Class name ForumInterceptorTemplated does not match with dto, rate: 44\n",
      "Class name ForumInterceptorTemplated does not match with handler, rate: 34\n",
      "Class name ForumInterceptorTemplated does not match with interceptor, rate: 64\n",
      "Class name ForumInterceptorTemplated does not match with mapper, rate: 38\n",
      "Class name ForumInterceptorTemplated does not match with model, rate: 35\n",
      "Class name ForumInterceptorTemplated does not match with service, rate: 58\n",
      "Class name ForumInterceptorTemplated does not match with util, rate: 33\n",
      "Class ForumInterceptorTemplated not found in any package.\n",
      "Class name GoodMapper does not match with config, rate: 29\n",
      "Class name GoodMapper does not match with controller, rate: 33\n",
      "Class name GoodMapper does not match with dto, rate: 43\n",
      "Class name GoodMapper does not match with handler, rate: 38\n",
      "Class name GoodMapper does not match with interceptor, rate: 30\n",
      "Class name Errand does not match with config, rate: 17\n",
      "Class name Errand does not match with controller, rate: 55\n",
      "Class name Errand does not match with dto, rate: 52\n",
      "Class name Errand does not match with handler, rate: 29\n",
      "Class name Errand does not match with interceptor, rate: 38\n",
      "Class name Errand does not match with mapper, rate: 67\n",
      "Class name ErrandOrderStatus does not match with config, rate: 34\n",
      "Class name ErrandOrderStatus does not match with controller, rate: 55\n",
      "Class name Shop does not match with config, rate: 27\n",
      "Class name Shop does not match with controller, rate: 44\n",
      "Class name Shop does not match with dto, rate: 67\n",
      "Class name Shop does not match with handler, rate: 15\n",
      "Class name Shop does not match with interceptor, rate: 21\n",
      "Class name Shop does not match with mapper, rate: 57\n",
      "Class name ComplaintRequest does not match with config, rate: 40\n",
      "Class name ComplaintRequest does not match with controller, rate: 57\n",
      "Class name ApiInterceptor does not match with config, rate: 36\n",
      "Class name ApiInterceptor does not match with controller, rate: 47\n",
      "Class name ApiInterceptor does not match with dto, rate: 48\n",
      "Class name ApiInterceptor does not match with handler, rate: 33\n",
      "Class name RegisterService does not match with config, rate: 48\n",
      "Class name RegisterService does not match with controller, rate: 61\n",
      "Class name RegisterService does not match with dto, rate: 67\n",
      "Class name RegisterService does not match with handler, rate: 22\n",
      "Class name RegisterService does not match with interceptor, rate: 41\n",
      "Class name RegisterService does not match with mapper, rate: 44\n",
      "Class name RegisterService does not match with model, rate: 36\n",
      "Class name TemplatedErrandInterceptor does not match with config, rate: 40\n",
      "Class name TemplatedErrandInterceptor does not match with controller, rate: 52\n",
      "Class name TemplatedErrandInterceptor does not match with dto, rate: 45\n",
      "Class name TemplatedErrandInterceptor does not match with handler, rate: 38\n",
      "Class name BanMapper does not match with config, rate: 26\n",
      "Class name BanMapper does not match with controller, rate: 32\n",
      "Class name BanMapper does not match with dto, rate: 31\n",
      "Class name BanMapper does not match with handler, rate: 32\n",
      "Class name BanMapper does not match with interceptor, rate: 46\n",
      "Class name UploadFileSystemService does not match with config, rate: 32\n",
      "Class name UploadFileSystemService does not match with controller, rate: 33\n",
      "Class name UploadFileSystemService does not match with dto, rate: 36\n",
      "Class name UploadFileSystemService does not match with handler, rate: 36\n",
      "Class name UploadFileSystemService does not match with interceptor, rate: 42\n",
      "Class name UploadFileSystemService does not match with mapper, rate: 40\n",
      "Class name UploadFileSystemService does not match with model, rate: 33\n",
      "Class name Complaint does not match with config, rate: 43\n",
      "Class name Complaint does not match with controller, rate: 64\n",
      "Class name Complaint does not match with dto, rate: 78\n",
      "Class name Complaint does not match with handler, rate: 26\n",
      "Class name Complaint does not match with interceptor, rate: 38\n",
      "Class name Complaint does not match with mapper, rate: 75\n",
      "Class name ComplaintDTOMapper does not match with config, rate: 38\n",
      "Class name ComplaintDTOMapper does not match with controller, rate: 59\n",
      "Class name ComplaintDTOMapper does not match with dto, rate: 59\n",
      "Class name ComplaintDTOMapper does not match with handler, rate: 35\n",
      "Class name ComplaintDTOMapper does not match with interceptor, rate: 39\n",
      "Class name ForumController does not match with config, rate: 36\n",
      "Class name LikeBlog does not match with config, rate: 35\n",
      "Class name LikeBlog does not match with controller, rate: 26\n",
      "Class name LikeBlog does not match with dto, rate: 36\n",
      "Class name LikeBlog does not match with handler, rate: 13\n",
      "Class name LikeBlog does not match with interceptor, rate: 27\n",
      "Class name LikeBlog does not match with mapper, rate: 73\n",
      "Class name ViewInterceptor does not match with config, rate: 30\n",
      "Class name ViewInterceptor does not match with controller, rate: 42\n",
      "Class name ViewInterceptor does not match with dto, rate: 40\n",
      "Class name ViewInterceptor does not match with handler, rate: 32\n",
      "Class name ErrorController does not match with config, rate: 36\n",
      "Class name ComplaintController does not match with config, rate: 40\n",
      "Class name ProductTransaction does not match with config, rate: 33\n",
      "Class name ProductTransaction does not match with controller, rate: 36\n",
      "Class name ReplyTreeNode does not match with config, rate: 37\n",
      "Class name ReplyTreeNode does not match with controller, rate: 34\n",
      "Class name ReplyTreeNode does not match with dto, rate: 55\n",
      "Class name ReplyTreeNode does not match with handler, rate: 29\n",
      "Class name ReplyTreeNode does not match with interceptor, rate: 37\n",
      "Class name ReplyTreeNode does not match with mapper, rate: 50\n",
      "Class name BanApiInterceptor does not match with config, rate: 32\n",
      "Class name BanApiInterceptor does not match with controller, rate: 42\n",
      "Class name BanApiInterceptor does not match with dto, rate: 43\n",
      "Class name BanApiInterceptor does not match with handler, rate: 36\n",
      "Class name Order does not match with config, rate: 26\n",
      "Class name Order does not match with controller, rate: 38\n",
      "Class name AlipayConfigMapper does not match with config, rate: 55\n",
      "Class name AlipayConfigMapper does not match with controller, rate: 65\n",
      "Class name AlipayConfigMapper does not match with dto, rate: 41\n",
      "Class name AlipayConfigMapper does not match with handler, rate: 35\n",
      "Class name AlipayConfigMapper does not match with interceptor, rate: 31\n",
      "Class name BanBlock does not match with config, rate: 21\n",
      "Class name BanBlock does not match with controller, rate: 26\n",
      "Class name BanBlock does not match with dto, rate: 64\n",
      "Class name BanBlock does not match with handler, rate: 20\n",
      "Class name BanBlock does not match with interceptor, rate: 33\n",
      "Class name BanBlock does not match with mapper, rate: 35\n",
      "Class name GlobalExceptionHandler does not match with config, rate: 33\n",
      "Class name GlobalExceptionHandler does not match with controller, rate: 39\n",
      "Class name GlobalExceptionHandler does not match with dto, rate: 35\n",
      "Class name ReplyMapperStruct does not match with config, rate: 34\n",
      "Class name ReplyMapperStruct does not match with controller, rate: 34\n",
      "Class name ReplyMapperStruct does not match with dto, rate: 47\n",
      "Class name ReplyMapperStruct does not match with handler, rate: 26\n",
      "Class name ReplyMapperStruct does not match with interceptor, rate: 48\n",
      "Class name UserService does not match with config, rate: 41\n",
      "Class name UserService does not match with controller, rate: 48\n",
      "Class name UserService does not match with dto, rate: 44\n",
      "Class name UserService does not match with handler, rate: 18\n",
      "Class name UserService does not match with interceptor, rate: 38\n",
      "Class name UserService does not match with mapper, rate: 57\n",
      "Class name UserService does not match with model, rate: 53\n",
      "Class name Visibility does not match with config, rate: 25\n",
      "Class name Visibility does not match with controller, rate: 29\n",
      "Class name OrderDTO does not match with config, rate: 23\n",
      "Class name OrderDTO does not match with controller, rate: 33\n",
      "Class name ReplyTreeConverter does not match with config, rate: 44\n",
      "Class name ReplyTreeConverter does not match with controller, rate: 50\n",
      "Class name ReplyTreeConverter does not match with dto, rate: 45\n",
      "Class name ReplyTreeConverter does not match with handler, rate: 30\n",
      "Class name ReplyTreeConverter does not match with interceptor, rate: 47\n",
      "Class name ReplyTreeConverter does not match with mapper, rate: 51\n",
      "Class name ReplyTreeConverter does not match with model, rate: 71\n",
      "Class name ReplyTreeConverter does not match with service, rate: 41\n",
      "Class name ShopInfo does not match with config, rate: 35\n",
      "Class name ShopInfo does not match with controller, rate: 55\n",
      "Class name BasicInterceptor does not match with config, rate: 29\n",
      "Class name BasicInterceptor does not match with controller, rate: 41\n",
      "Class name BasicInterceptor does not match with dto, rate: 44\n",
      "Class name BasicInterceptor does not match with handler, rate: 37\n",
      "Class name StockController does not match with config, rate: 42\n",
      "Class name PostSortOrder does not match with config, rate: 39\n",
      "Class name PostSortOrder does not match with controller, rate: 45\n",
      "Class name UserMapper does not match with config, rate: 36\n",
      "Class name UserMapper does not match with controller, rate: 50\n",
      "Class name UserMapper does not match with dto, rate: 40\n",
      "Class name UserMapper does not match with handler, rate: 25\n",
      "Class name UserMapper does not match with interceptor, rate: 38\n",
      "Class name OrderMapper does not match with config, rate: 34\n",
      "Class name OrderMapper does not match with controller, rate: 37\n",
      "Class name OrderMapper does not match with dto, rate: 62\n",
      "Class name OrderMapper does not match with handler, rate: 24\n",
      "Class name OrderMapper does not match with interceptor, rate: 32\n",
      "Class name Charge does not match with config, rate: 27\n",
      "Class name Charge does not match with controller, rate: 32\n",
      "Class name Charge does not match with dto, rate: 36\n",
      "Class name Charge does not match with handler, rate: 14\n",
      "Class name Charge does not match with interceptor, rate: 29\n",
      "Class name Charge does not match with mapper, rate: 67\n",
      "Class name RegisterController does not match with config, rate: 39\n",
      "Class name LoginController does not match with config, rate: 38\n",
      "Class name TransactionMapper does not match with config, rate: 34\n",
      "Class name TransactionMapper does not match with controller, rate: 42\n",
      "Class name TransactionMapper does not match with dto, rate: 63\n",
      "Class name TransactionMapper does not match with handler, rate: 46\n",
      "Class name TransactionMapper does not match with interceptor, rate: 37\n",
      "Class name ComplaintMapper does not match with config, rate: 41\n",
      "Class name ComplaintMapper does not match with controller, rate: 65\n",
      "Class name ComplaintMapper does not match with dto, rate: 65\n",
      "Class name ComplaintMapper does not match with handler, rate: 38\n",
      "Class name ComplaintMapper does not match with interceptor, rate: 42\n",
      "Class name TemplatedBanInterceptor does not match with config, rate: 43\n",
      "Class name TemplatedBanInterceptor does not match with controller, rate: 48\n",
      "Class name TemplatedBanInterceptor does not match with dto, rate: 46\n",
      "Class name TemplatedBanInterceptor does not match with handler, rate: 36\n",
      "Class name ReplyMapper does not match with config, rate: 40\n",
      "Class name ReplyMapper does not match with controller, rate: 34\n",
      "Class name ReplyMapper does not match with dto, rate: 60\n",
      "Class name ReplyMapper does not match with handler, rate: 30\n",
      "Class name ReplyMapper does not match with interceptor, rate: 35\n",
      "Class name ReportRequest does not match with config, rate: 39\n",
      "Class name ReportRequest does not match with controller, rate: 33\n",
      "Class name Reply does not match with config, rate: 32\n",
      "Class name Reply does not match with controller, rate: 26\n",
      "Class name Reply does not match with dto, rate: 71\n",
      "Class name Reply does not match with handler, rate: 22\n",
      "Class name Reply does not match with interceptor, rate: 21\n",
      "Class name Reply does not match with mapper, rate: 62\n",
      "Class name RegisterRequest does not match with config, rate: 42\n",
      "Class name RegisterRequest does not match with controller, rate: 55\n",
      "Class name LocalUploadFileSystemService does not match with config, rate: 33\n",
      "Class name LocalUploadFileSystemService does not match with controller, rate: 34\n",
      "Class name LocalUploadFileSystemService does not match with dto, rate: 36\n",
      "Class name LocalUploadFileSystemService does not match with handler, rate: 40\n",
      "Class name LocalUploadFileSystemService does not match with interceptor, rate: 38\n",
      "Class name LocalUploadFileSystemService does not match with mapper, rate: 37\n",
      "Class name LocalUploadFileSystemService does not match with model, rate: 32\n",
      "Class name UserController does not match with config, rate: 44\n",
      "Class name ErrandOrderPreview does not match with config, rate: 39\n",
      "Class name ErrandOrderPreview does not match with controller, rate: 53\n",
      "Class name BlogMapper does not match with config, rate: 33\n",
      "Class name BlogMapper does not match with controller, rate: 33\n",
      "Class name BlogMapper does not match with dto, rate: 29\n",
      "Class name BlogMapper does not match with handler, rate: 38\n",
      "Class name BlogMapper does not match with interceptor, rate: 37\n",
      "Class name StockService does not match with config, rate: 47\n",
      "Class name StockService does not match with controller, rate: 52\n",
      "Class name StockService does not match with dto, rate: 36\n",
      "Class name StockService does not match with handler, rate: 29\n",
      "Class name StockService does not match with interceptor, rate: 38\n",
      "Class name StockService does not match with mapper, rate: 36\n",
      "Class name StockService does not match with model, rate: 38\n",
      "Class name LikeBlogMapper does not match with config, rate: 36\n",
      "Class name LikeBlogMapper does not match with controller, rate: 34\n",
      "Class name LikeBlogMapper does not match with dto, rate: 32\n",
      "Class name LikeBlogMapper does not match with handler, rate: 33\n",
      "Class name LikeBlogMapper does not match with interceptor, rate: 32\n",
      "Class name ForumPostPreview does not match with config, rate: 41\n",
      "Class name ForumPostPreview does not match with controller, rate: 58\n",
      "Class name BlogToForumPostPreview does not match with config, rate: 35\n",
      "Class name BlogToForumPostPreview does not match with controller, rate: 49\n",
      "Class name ShopMapper does not match with config, rate: 36\n",
      "Class name ShopMapper does not match with controller, rate: 50\n",
      "Class name ShopMapper does not match with dto, rate: 44\n",
      "Class name ShopMapper does not match with handler, rate: 31\n",
      "Class name ShopMapper does not match with interceptor, rate: 30\n",
      "Class name ComplaintBlock does not match with config, rate: 36\n",
      "Class name ComplaintBlock does not match with controller, rate: 61\n",
      "Class name AlipayController does not match with config, rate: 53\n",
      "Class name Blog does not match with config, rate: 31\n",
      "Class name Blog does not match with controller, rate: 21\n",
      "Class name Blog does not match with dto, rate: 33\n",
      "Class name Blog does not match with handler, rate: 15\n",
      "Class name Blog does not match with interceptor, rate: 20\n",
      "Class name Blog does not match with mapper, rate: 57\n",
      "Class name LoginRequest does not match with config, rate: 27\n",
      "Class name LoginRequest does not match with controller, rate: 44\n",
      "Class name ErrandMapper does not match with config, rate: 33\n",
      "Class name ErrandMapper does not match with controller, rate: 57\n",
      "Class name ErrandMapper does not match with dto, rate: 55\n",
      "Class name ErrandMapper does not match with handler, rate: 35\n",
      "Class name ErrandMapper does not match with interceptor, rate: 42\n",
      "Class name ErrandInterceptorTemplated does not match with config, rate: 45\n",
      "Class name ErrandInterceptorTemplated does not match with controller, rate: 57\n",
      "Class name ErrandInterceptorTemplated does not match with dto, rate: 51\n",
      "Class name ErrandInterceptorTemplated does not match with handler, rate: 33\n",
      "Class name ErrandInterceptorTemplated does not match with interceptor, rate: 65\n",
      "Class name ErrandInterceptorTemplated does not match with mapper, rate: 47\n",
      "Class name ErrandInterceptorTemplated does not match with model, rate: 38\n",
      "Class name ErrandInterceptorTemplated does not match with service, rate: 60\n",
      "Class name ErrandInterceptorTemplated does not match with util, rate: 32\n",
      "Class ErrandInterceptorTemplated not found in any package.\n",
      "Class name ExceptionMapper does not match with config, rate: 36\n",
      "Class name ExceptionMapper does not match with controller, rate: 38\n",
      "Class name ExceptionMapper does not match with dto, rate: 38\n",
      "Class name ExceptionMapper does not match with handler, rate: 65\n",
      "Class name ExceptionMapper does not match with interceptor, rate: 41\n",
      "Class name SessionKeys does not match with config, rate: 41\n",
      "Class name log does not match with config, rate: 33\n",
      "Class name log does not match with controller, rate: 22\n",
      "Class name log does not match with dto, rate: 27\n",
      "Class name log does not match with handler, rate: 16\n",
      "Class name log does not match with interceptor, rate: 15\n",
      "Class name log does not match with mapper, rate: 46\n",
      "Class name AuthInterceptor does not match with config, rate: 30\n",
      "Class name AuthInterceptor does not match with controller, rate: 41\n",
      "Class name AuthInterceptor does not match with dto, rate: 36\n",
      "Class name AuthInterceptor does not match with handler, rate: 32\n",
      "Class name VerifyRequest does not match with config, rate: 45\n",
      "Class name VerifyRequest does not match with controller, rate: 33\n",
      "Class name ShopOrder does not match with config, rate: 37\n",
      "Class name ShopOrder does not match with controller, rate: 61\n",
      "Class name ShopOrder does not match with dto, rate: 71\n",
      "Class name ShopOrder does not match with handler, rate: 32\n",
      "Class name ShopOrder does not match with interceptor, rate: 35\n",
      "Class name ShopOrder does not match with mapper, rate: 63\n",
      "Class name ErrandViewsMapper does not match with config, rate: 29\n",
      "Class name ErrandViewsMapper does not match with controller, rate: 48\n",
      "Class name ErrandViewsMapper does not match with dto, rate: 51\n",
      "Class name ErrandViewsMapper does not match with handler, rate: 31\n",
      "Class name ErrandViewsMapper does not match with interceptor, rate: 42\n",
      "Class name BaseAuthService does not match with config, rate: 42\n",
      "Class name BaseAuthService does not match with controller, rate: 34\n",
      "Class name BaseAuthService does not match with dto, rate: 39\n",
      "Class name BaseAuthService does not match with handler, rate: 27\n",
      "Class name BaseAuthService does not match with interceptor, rate: 53\n",
      "Class name BaseAuthService does not match with mapper, rate: 38\n",
      "Class name BaseAuthService does not match with model, rate: 32\n",
      "Class name ExceptionService does not match with config, rate: 41\n",
      "Class name ExceptionService does not match with controller, rate: 37\n",
      "Class name ExceptionService does not match with dto, rate: 41\n",
      "Class name ExceptionService does not match with handler, rate: 58\n",
      "Class name ExceptionService does not match with interceptor, rate: 47\n",
      "Class name ExceptionService does not match with mapper, rate: 71\n",
      "Class name ExceptionService does not match with model, rate: 32\n",
      "Class name ComplaintService does not match with config, rate: 40\n",
      "Class name ComplaintService does not match with controller, rate: 63\n",
      "Class name ComplaintService does not match with dto, rate: 69\n",
      "Class name ComplaintService does not match with handler, rate: 32\n",
      "Class name ComplaintService does not match with interceptor, rate: 53\n",
      "Class name ComplaintService does not match with mapper, rate: 71\n",
      "Class name ComplaintService does not match with model, rate: 72\n",
      "Class name ChargeMapper does not match with config, rate: 31\n",
      "Class name ChargeMapper does not match with controller, rate: 32\n",
      "Class name ChargeMapper does not match with dto, rate: 35\n",
      "Class name ChargeMapper does not match with handler, rate: 29\n",
      "Class name ChargeMapper does not match with interceptor, rate: 37\n",
      "Class name GoodTransaction does not match with config, rate: 31\n",
      "Class name GoodTransaction does not match with controller, rate: 35\n",
      "Class name GoodTransaction does not match with dto, rate: 79\n",
      "Class name GoodTransaction does not match with handler, rate: 43\n",
      "Class name GoodTransaction does not match with interceptor, rate: 34\n",
      "Class name GoodTransaction does not match with mapper, rate: 77\n",
      "Class name BanInterceptor does not match with config, rate: 31\n",
      "Class name BanInterceptor does not match with controller, rate: 47\n",
      "Class name BanInterceptor does not match with dto, rate: 40\n",
      "Class name BanInterceptor does not match with handler, rate: 39\n",
      "Class name ReplyView does not match with config, rate: 35\n",
      "Class name ReplyView does not match with controller, rate: 30\n",
      "Class name ShopService does not match with config, rate: 48\n",
      "Class name ShopService does not match with controller, rate: 48\n",
      "Class name ShopService does not match with dto, rate: 42\n",
      "Class name ShopService does not match with handler, rate: 24\n",
      "Class name ShopService does not match with interceptor, rate: 40\n",
      "Class name ShopService does not match with mapper, rate: 57\n",
      "Class name ShopService does not match with model, rate: 60\n",
      "Class name MailService does not match with config, rate: 34\n",
      "Class name MailService does not match with controller, rate: 36\n",
      "Class name MailService does not match with dto, rate: 41\n",
      "Class name MailService does not match with handler, rate: 30\n",
      "Class name MailService does not match with interceptor, rate: 44\n",
      "Class name MailService does not match with mapper, rate: 40\n",
      "Class name MailService does not match with model, rate: 35\n",
      "Class name ApiResponse does not match with config, rate: 40\n",
      "Class name ApiResponse does not match with controller, rate: 45\n",
      "Class name ErrandOrderRequest does not match with config, rate: 33\n",
      "Class name ErrandOrderRequest does not match with controller, rate: 53\n",
      "Class name Ban does not match with config, rate: 17\n",
      "Class name Ban does not match with controller, rate: 21\n",
      "Class name Ban does not match with dto, rate: 24\n",
      "Class name Ban does not match with handler, rate: 16\n",
      "Class name Ban does not match with interceptor, rate: 32\n",
      "Class name Ban does not match with mapper, rate: 50\n",
      "Class name LoginService does not match with config, rate: 33\n",
      "Class name LoginService does not match with controller, rate: 52\n",
      "Class name LoginService does not match with dto, rate: 58\n",
      "Class name LoginService does not match with handler, rate: 29\n",
      "Class name LoginService does not match with interceptor, rate: 46\n",
      "Class name LoginService does not match with mapper, rate: 38\n",
      "Class name LoginService does not match with model, rate: 30\n",
      "Class name TemplatedForumInterceptor does not match with config, rate: 41\n",
      "Class name TemplatedForumInterceptor does not match with controller, rate: 50\n",
      "Class name TemplatedForumInterceptor does not match with dto, rate: 44\n",
      "Class name TemplatedForumInterceptor does not match with handler, rate: 34\n",
      "Class name User does not match with config, rate: 18\n",
      "Class name User does not match with controller, rate: 44\n",
      "Class name User does not match with dto, rate: 44\n",
      "Class name User does not match with handler, rate: 15\n",
      "Class name User does not match with interceptor, rate: 30\n",
      "Class name User does not match with mapper, rate: 57\n",
      "Class name KeywordType does not match with config, rate: 34\n",
      "Class name KeywordType does not match with controller, rate: 32\n",
      "Class name ShopController does not match with config, rate: 38\n",
      "Class name ProductToGoodTransaction does not match with config, rate: 29\n",
      "Class name ProductToGoodTransaction does not match with controller, rate: 31\n",
      "Class name ErrandService does not match with config, rate: 39\n",
      "Class name ErrandService does not match with controller, rate: 55\n",
      "Class name ErrandService does not match with dto, rate: 71\n",
      "Class name ErrandService does not match with handler, rate: 34\n",
      "Class name ErrandService does not match with interceptor, rate: 51\n",
      "Class name ErrandService does not match with mapper, rate: 64\n",
      "Class name ErrandService does not match with model, rate: 63\n",
      "Class name ChargeService does not match with config, rate: 32\n",
      "Class name ChargeService does not match with controller, rate: 33\n",
      "Class name ChargeService does not match with dto, rate: 45\n",
      "Class name ChargeService does not match with handler, rate: 23\n",
      "Class name ChargeService does not match with interceptor, rate: 36\n",
      "Class name ChargeService does not match with mapper, rate: 64\n",
      "Class name ChargeService does not match with model, rate: 63\n",
      "Class name ForumPostService does not match with config, rate: 41\n",
      "Class name ForumPostService does not match with controller, rate: 58\n",
      "Class name CampusAidException does not match with config, rate: 34\n",
      "Class name CampusAidException does not match with controller, rate: 38\n",
      "Class name CampusAidException does not match with dto, rate: 41\n",
      "Class name CampusAidException does not match with handler, rate: 50\n",
      "Class name CampusAidException does not match with interceptor, rate: 47\n",
      "Class name CampusAidException does not match with mapper, rate: 55\n",
      "Class name CampusAidException does not match with model, rate: 42\n",
      "Class name Good does not match with config, rate: 15\n",
      "Class name Good does not match with controller, rate: 22\n",
      "Class name Good does not match with dto, rate: 35\n",
      "Class name Good does not match with handler, rate: 31\n",
      "Class name Good does not match with interceptor, rate: 14\n",
      "Class name Good does not match with mapper, rate: 57\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.414322Z",
     "start_time": "2025-05-26T06:32:19.343186Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import requests, uuid, json, datetime\n",
    "\n",
    "\n",
    "def translate(text: str = 'I would really like to drive your car around the block a few times!'):\n",
    "    # Add your key and endpoint\n",
    "    key = r\"57fS7GWF6wt0Vi87Ztdsz9pbrO5KTRPSp6EbIZpgevSxZQjqaRP0JQQJ99BEACqBBLyXJ3w3AAAbACOG0qD1\"\n",
    "    # key=\"5176133b-9440-4c22-b79f-e1693927ef5b\"\n",
    "    endpoint = \"https://api.cognitive.microsofttranslator.com\"\n",
    "\n",
    "    # location, also known as region.\n",
    "    # required if you're using a multi-service or regional (not global) resource. It can be found in the Azure portal on the Keys and Endpoint page.\n",
    "    location = \"southeastasia\"\n",
    "\n",
    "    path = '/translate'\n",
    "    constructed_url = endpoint + path\n",
    "\n",
    "    params = {\n",
    "        'api-version': '3.0',\n",
    "        'from': 'en',\n",
    "        'to': ['zh', 'zu'],\n",
    "    }\n",
    "\n",
    "    headers = {\n",
    "        'Ocp-Apim-Subscription-Key': key,\n",
    "        # location required if you're using a multi-service or regional (not global) resource.\n",
    "        'Ocp-Apim-Subscription-Region': location,\n",
    "        'Content-type': 'application/json',\n",
    "        'X-ClientTraceId': str(uuid.uuid4()),\n",
    "    }\n",
    "\n",
    "    # You can pass more than one object in body.\n",
    "    body = [{\n",
    "        'text': text\n",
    "    },\n",
    "        #     {\n",
    "        #     'text': 'verify by administrator'\n",
    "        # }\n",
    "    ]\n",
    "\n",
    "    request = requests.post(constructed_url, params=params, headers=headers, json=body)\n",
    "    response = request.json()\n",
    "    # print(datetime.datetime.now())\n",
    "    # print(json.dumps(response, sort_keys=True, ensure_ascii=False, indent=4, separators=(',', ': ')))\n",
    "    translations = response[0][\"translations\"]\n",
    "    # print(translations)\n",
    "    translation = [translation for translation in translations if 'zh' in str(translation[\"to\"]).lower()]\n",
    "    text = translation[0][\"text\"]\n",
    "    # print(text)\n",
    "    return text\n",
    "\n",
    "# translate()"
   ],
   "id": "378c1a52a69e25d0",
   "outputs": [],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.434136Z",
     "start_time": "2025-05-26T06:32:19.427166Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def translate_batch(batch: list[str], index: int) -> list[str]:\n",
    "    # Add your key and endpoint\n",
    "    key = r\"57fS7GWF6wt0Vi87Ztdsz9pbrO5KTRPSp6EbIZpgevSxZQjqaRP0JQQJ99BEACqBBLyXJ3w3AAAbACOG0qD1\"\n",
    "    # key=\"5176133b-9440-4c22-b79f-e1693927ef5b\"\n",
    "    endpoint = \"https://api.cognitive.microsofttranslator.com\"\n",
    "\n",
    "    # location, also known as region.\n",
    "    # required if you're using a multi-service or regional (not global) resource. It can be found in the Azure portal on the Keys and Endpoint page.\n",
    "    location = \"southeastasia\"\n",
    "\n",
    "    path = '/translate'\n",
    "    constructed_url = endpoint + path\n",
    "\n",
    "    params = {\n",
    "        'api-version': '3.0',\n",
    "        'from': 'en',\n",
    "        'to': ['zh'],\n",
    "    }\n",
    "\n",
    "    headers = {\n",
    "        'Ocp-Apim-Subscription-Key': key,\n",
    "        # location required if you're using a multi-service or regional (not global) resource.\n",
    "        'Ocp-Apim-Subscription-Region': location,\n",
    "        'Content-type': 'application/json',\n",
    "        'X-ClientTraceId': str(uuid.uuid4()),\n",
    "    }\n",
    "\n",
    "    # You can pass more than one object in body.\n",
    "    body = [\n",
    "    ]\n",
    "    for text in batch:\n",
    "        body.append({\n",
    "            'text': regularize_text_to_be_translated(text)\n",
    "        })\n",
    "\n",
    "    request = requests.post(constructed_url, params=params, headers=headers, json=body)\n",
    "    response = request.json()\n",
    "    \"\"\"\n",
    "    [{'translations': [{'text': '获取用户信息', 'to': 'zh-Hans'}]}, {'translations': [{'text': '获取 Target 用户 ID', 'to': 'zh-Hans'}]}, {'translations': [{'text': '可用用户 ID', 'to': 'zh-Hans'}]}, {'translations': [{'text': '按 ID 获取用户', 'to': 'zh-Hans'}]}, {'translations': [{'text': '目标用户', 'to': 'zh-Hans'}]}, {'translations': [{'text': '设置平衡', 'to': 'zh-Hans'}]}, {'translations': [{'text': '目标用户', 'to': 'zh-Hans'}]}, {'translations': [{'text': '上传帖子', 'to': 'zh-Hans'}]}, {'translations': [{'text': '获取用户目录', 'to': 'zh-Hans'}]}, {'translations': [{'text': '迪尔', 'to': 'zh-Hans'}]}, {'translations': [{'text': '上传文件', 'to': 'zh-Hans'}]}, {'translations': [{'text': 'URI', 'to': 'zh-Hans'}]}, {'translations': [{'text': '响应实体', 'to': 'zh-Hans'}]}, {'translations': [{'text': '获取上传的帖子', 'to': 'zh-Hans'}]}, {'translations': [{'text': '获取用户目录', 'to': 'zh-Hans'}]}, {'translations': [{'text': '迪尔', 'to': 'zh-Hans'}]}, {'translations': [{'text': '列出文件', 'to': 'zh-Hans'}]}, {'translations': [{'text': '响应实体', 'to': 'zh-Hans'}]}]\n",
    "    \"\"\"\n",
    "    # print(datetime.datetime.now())\n",
    "    # print(json.dumps(response, sort_keys=True, ensure_ascii=False, indent=4, separators=(',', ': ')))\n",
    "    print(response)\n",
    "    if (type(response) == dict and 'error' in response.keys()):\n",
    "        import sys\n",
    "        print(\"\" + str(index) + \"--\" + str(response[\"error\"]) + str(body), file=sys.stderr)\n",
    "\n",
    "        return []\n",
    "    if type(response) == list:\n",
    "        if len(response) == 0:\n",
    "            import sys\n",
    "            print(\"\" + str(index) + \"--\" + str(response[\"error\"]) + str(body), file=sys.stderr)\n",
    "\n",
    "            return []\n",
    "        if len(response) == 1 and 'error' in response[0].keys():\n",
    "            import sys\n",
    "            print(\"\" + str(index) + \"--\" + str(response[\"error\"]) + str(body), file=sys.stderr)\n",
    "\n",
    "            return []\n",
    "    translations = [response_obj[\"translations\"] for response_obj in response]\n",
    "    print(\"i.e.\")\n",
    "    print(translations)\n",
    "    # print(translations)\n",
    "    translations_filtered = [translation[0] for translation in translations if\n",
    "                             'zh' in str(translation[0][\"to\"]).lower()]\n",
    "    texts = [translation[\"text\"] for translation in translations_filtered]\n",
    "    # print(text)\n",
    "    return texts"
   ],
   "id": "27fa6e85417f0479",
   "outputs": [],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.469094Z",
     "start_time": "2025-05-26T06:32:19.443262Z"
    }
   },
   "cell_type": "code",
   "source": [
    "refined_md_dir = pathlib.Path(\"refined_md_2\")\n",
    "if not refined_md_dir.exists():\n",
    "    refined_md_dir.mkdir()\n",
    "else:\n",
    "    shutil.rmtree(refined_md_dir)\n",
    "    refined_md_dir.mkdir()"
   ],
   "id": "e6848012",
   "outputs": [],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.481848Z",
     "start_time": "2025-05-26T06:32:19.478772Z"
    }
   },
   "cell_type": "code",
   "source": [
    "plant_uml_dir = pathlib.Path(\n",
    "    \"plantuml_\" + str(datetime.datetime.now()).replace(\" \", \"_\").replace(\":\", \"_\").replace(\".\", \"_\").replace(\"-\", \"_\"))\n",
    "if not plant_uml_dir.exists():\n",
    "    plant_uml_dir.mkdir()\n",
    "else:\n",
    "    shutil.rmtree(plant_uml_dir)\n",
    "    plant_uml_dir.mkdir()"
   ],
   "id": "1765a89f",
   "outputs": [],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.494549Z",
     "start_time": "2025-05-26T06:32:19.491581Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def contains_chinese(text):\n",
    "    for char in text:\n",
    "        if '\\u4e00' <= char <= '\\u9fff':\n",
    "            return True\n",
    "    return False"
   ],
   "id": "fe44600c50065c98",
   "outputs": [],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.511048Z",
     "start_time": "2025-05-26T06:32:19.505779Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def regularize_text_to_be_translated(text: str) -> str:\n",
    "    replaced = ['<', '>']\n",
    "    # verifyByAdmin to 'verify by admin'\n",
    "    outbuf = \"\"\n",
    "    # main_index = 0\n",
    "    consequent_upper = False\n",
    "    for main_index in range(len(text)):\n",
    "        if main_index >= len(text):\n",
    "            break\n",
    "        character = text[main_index]\n",
    "        if character.isupper():\n",
    "            if not consequent_upper:\n",
    "                outbuf += \" \" + character\n",
    "            else:\n",
    "                outbuf += character\n",
    "            consequent_upper = True\n",
    "        else:\n",
    "            outbuf += character if not character in replaced else \" \"\n",
    "            consequent_upper = False\n",
    "    return outbuf\n",
    "\n",
    "\n",
    "def replace_plantuml_illustrations_to_chinese(content: str) -> str:\n",
    "    lines = content.split(\"\\n\")\n",
    "    list_to_be_translated = []\n",
    "    # plantuml_outbuf = \"\"\n",
    "    plantuml_outbuf = content\n",
    "    # User -> ForumController: listPosts(keyword, type, sortBy, page)\n",
    "    # will be converted to\n",
    "    # User -> ForumController: 展示帖子/展示博客\n",
    "    for index, line in enumerate(lines):\n",
    "        match = True\n",
    "        # if contains_chinese(line):\n",
    "        #     continue\n",
    "        while True:\n",
    "            if not \":\" in line:\n",
    "                match = False\n",
    "                break\n",
    "            # User -> ForumController\n",
    "            to_be_kept_before = line.split(\":\")[0]\n",
    "            if not \"->\" in to_be_kept_before:\n",
    "                # just a guardian  for the case that there is no \":\"\n",
    "                match = False\n",
    "                break\n",
    "            altered = line[len(to_be_kept_before) + 1:]\n",
    "            to_be_translated = regularize_text_to_be_translated(altered.split(\"(\")[0])\n",
    "            list_to_be_translated.append(to_be_translated)\n",
    "            print(index, line, to_be_translated, sep=\"\\n\\t\")\n",
    "            break\n",
    "            # if not \")\" in altered[len(to_be_translated):]:\n",
    "            #     #  just a guardian for the case that there is no \")\"\n",
    "            #     match = False\n",
    "            #     break\n",
    "        #     translated = translate(to_be_translated)\n",
    "        #     plantuml_outbuf += to_be_kept_before + \" : \" + translated + \"\\n\"\n",
    "        #     print(\"\\n\\t<\"+translated+\">\")\n",
    "        #     break\n",
    "        # if not match:\n",
    "        #     plantuml_outbuf += line + \"\\n\"\n",
    "    result = translate_batch(list_to_be_translated, index)\n",
    "\n",
    "    print(result)\n",
    "    for i, translated in enumerate(result):\n",
    "        print(f\"{list_to_be_translated[i]}->{translated}\")\n",
    "        plantuml_outbuf = plantuml_outbuf.replace(list_to_be_translated[i], translated)\n",
    "    return plantuml_outbuf"
   ],
   "id": "3703ca95024d10fc",
   "outputs": [],
   "execution_count": 12
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:19.557123Z",
     "start_time": "2025-05-26T06:32:19.520449Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import plantuml\n",
    "\n",
    "plantuml_processor = plantuml.PlantUML(url='http://192.168.1.28:9900/plantuml/img/')\n",
    "plantuml_img_dir = pathlib.Path(\".\").parent / \"plantuml_img\"\n",
    "if not plantuml_img_dir.exists():\n",
    "    plantuml_img_dir.mkdir()\n",
    "\n",
    "\n",
    "def refine_md(class_name, index) -> tuple[str, str]:\n",
    "    md_file_path = pathlib.Path(\"md\") / f\"{class_name}.md\"\n",
    "    with open(md_file_path, \"r\", encoding=\"utf-8\") as f:\n",
    "        content = f.read()\n",
    "    main_content_index = len(content.split(\"#\")[0])\n",
    "    refined_content = content[main_content_index:]\n",
    "    refined_content = refined_content.replace(\"class 3\", class_name)\n",
    "    refined_content = refined_content.replace(\"class3\", class_name)\n",
    "    refined_content = refined_content.replace(\"class1\", class_name)\n",
    "    refined_content = refined_content.replace(\"class 1\", class_name)\n",
    "    refined_content = refined_content.replace(\"# 3\", f\"# {index}\")\n",
    "    plantuml_content = \"\".join(refined_content.split(\"```plantuml\")[1:]).split(\"```\")[0]\n",
    "\n",
    "\n",
    "\n",
    "    with (open(plant_uml_dir / f\"{index}--{class_name}.puml\", \"w\", encoding=\"utf-8\") as f):\n",
    "        translated_plantuml_content = plantuml_content\n",
    "        # translated_plantuml_content=replace_plantuml_illustrations_to_chinese(translated_plantuml_content)\n",
    "        f.write(translated_plantuml_content)\n",
    "    binary_content = plantuml_processor.processes(translated_plantuml_content)\n",
    "    target_pic_path = (plantuml_img_dir / f\"{index}--{class_name}.png\").as_posix()\n",
    "    with open(target_pic_path, \"wb\") as f:\n",
    "        f.write(binary_content)\n",
    "    plantuml_reference = f\"![{index}--{class_name}](../{target_pic_path})\"\n",
    "    refined_content = refined_content.replace(plantuml_content, \"\\n\\n\\n\\n\\n\")\n",
    "    refined_content = f\"# {index} {class_name}\\n\\n\" + refined_content.replace(\"```\", \"\").replace(\"plantuml\", plantuml_reference)\n",
    "    refined_content += \"\\n\\n\\n\"\n",
    "\n",
    "    with open(refined_md_dir / f\"{index}--{class_name}.md\", \"w\", encoding=\"utf-8\") as f:\n",
    "        f.write(refined_content)\n",
    "    return (refined_content,\n",
    "            refined_content.replace(plantuml_content, \"\\n\\n\\n\\n\\n\")\n",
    "            .replace(\"```\", \"\")\n",
    "            .replace(\"plantuml\", plantuml_reference)\n",
    "            )"
   ],
   "id": "773ac683",
   "outputs": [],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:23.095217Z",
     "start_time": "2025-05-26T06:32:19.566661Z"
    }
   },
   "cell_type": "code",
   "source": [
    "index = 3\n",
    "outbuf = \"\"\n",
    "prioritized_packages = []\n",
    "\n",
    "# prioritized_packages+=[ key for key in  packages.keys()\n",
    "#                         if not '.java' in key.lower()\n",
    "#                         and not \"dto\" in key.lower()\n",
    "#                         and not 'model' in key.lower()\n",
    "#                         ]\n",
    "\n",
    "prioritized_packages.append(\"controller\")\n",
    "prioritized_packages.append(\"service\")\n",
    "prioritized_packages.append(\"mapper\")\n",
    "briefed_outbuf = \"\"\n",
    "\n",
    "for package in prioritized_packages:\n",
    "    if not package in packages.keys():\n",
    "        raise FileNotFoundError(f\"Package {package} not found in any package.\")\n",
    "    print('\\n', package)\n",
    "    title = f\"\\n\\n# {package}\\n\"\n",
    "    outbuf += title\n",
    "    briefed_outbuf += title\n",
    "    for class_name in packages[package]:\n",
    "        print(class_name, ' ', index, end=\" \")\n",
    "\n",
    "        refined, raw = refine_md(class_name, index)\n",
    "        outbuf += refined\n",
    "        briefed_outbuf += refined\n",
    "        index += 1\n",
    "\n",
    "# briefed_outbuf = ''\n",
    "outbuf=''\n",
    "for package in packages.keys():\n",
    "    if package in prioritized_packages:\n",
    "        continue\n",
    "    print('\\n', package)\n",
    "    outbuf += f\"\\n# {package}\\n\"\n",
    "    for class_name in packages[package]:\n",
    "        print(class_name, ' ', index, end=\" \")\n",
    "        index += 1\n",
    "        refined, raw = refine_md(class_name, index)\n",
    "        outbuf += refined.replace(\"\\n\\n\\n\\n\\n\\n\",\"\")\n"
   ],
   "id": "41d8c8f3",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " controller\n",
      "RegisterController   3 ComplaintController   4 ErrandController   5 ForumController   6 StockController   7 AlipayController   8 ErrorController   9 ShopController   10 UserController   11 LoginController   12 \n",
      " service\n",
      "CampusAidException   13 MailService   14 ComplaintService   15 StockService   16 LoginService   17 UploadFileSystemService   18 LocalUploadFileSystemService   19 BaseAuthService   20 ChargeService   21 RegisterService   22 ErrandService   23 ShopService   24 UserService   25 ExceptionService   26 \n",
      " mapper\n",
      "GoodMapper   27 LikeBlogMapper   28 ExceptionMapper   29 ReplyMapper   30 ErrandMapper   31 ReplyMapperStruct   32 ComplaintDTOMapper   33 ErrandViewsMapper   34 ComplaintMapper   35 OrderMapper   36 UserMapper   37 ChargeMapper   38 ShopMapper   39 BlogMapper   40 BanMapper   41 AlipayConfigMapper   42 TransactionMapper   43 \n",
      " model\n",
      "Errand   44 GoodTransaction   45 User   46 Complaint   47 Charge   48 Shop   49 log   50 Good   51 Ban   52 ReplyTreeNode   53 Blog   54 ShopOrder   55 LikeBlog   56 Reply   57 BanBlock   58 \n",
      " dto\n",
      "OrderDTO   59 ShopInfo   60 SessionKeys   61 Order   62 PostSortOrder   63 ComplaintBlock   64 BlogToForumPostPreview   65 ProductTransaction   66 ErrandOrderRequest   67 ErrandOrderPreview   68 ComplaintRequest   69 VerifyRequest   70 RegisterRequest   71 ProductToGoodTransaction   72 ForumPostPreview   73 LoginRequest   74 KeywordType   75 ErrandOrderStatus   76 ForumPostService   77 ApiResponse   78 ReportRequest   79 Visibility   80 ReplyView   81 \n",
      " interceptor\n",
      "TemplatedBanInterceptor   82 AuthInterceptor   83 TemplatedErrandInterceptor   84 BanInterceptor   85 TemplatedForumInterceptor   86 ApiInterceptor   87 BasicInterceptor   88 ViewInterceptor   89 BanApiInterceptor   90 \n",
      " config\n",
      "SecurityProperties   91 AdminConfig   92 AlipayTemplate   93 WebConfig   94 \n",
      " handler\n",
      "GlobalExceptionHandler   95 \n",
      " util\n",
      "ReplyTreeConverter   96 "
     ]
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:23.221869Z",
     "start_time": "2025-05-26T06:32:23.107511Z"
    }
   },
   "cell_type": "code",
   "source": [
    "integrated_dir = pathlib.Path(\"integrated_v2\")\n",
    "if not integrated_dir.exists():\n",
    "    integrated_dir.mkdir()\n",
    "else:\n",
    "    # shutil.rmtree(integrated_dir)\n",
    "    # integrated_dir.mkdir()\n",
    "    pass\n",
    "\n",
    "with open(integrated_dir / \"left_index.md\", \"w\", encoding=\"utf-8\") as f:\n",
    "    f.write(outbuf)\n",
    "    print(outbuf)\n",
    "briefed_md_file = integrated_dir / \"briefed_index.md\"\n",
    "briefed_md_file = integrated_dir / \"all.md\"\n",
    "with open(briefed_md_file, \"w\", encoding=\"utf-8\") as f:\n",
    "    f.write(briefed_outbuf)\n",
    "# Convert the integrated markdown file to docx\n"
   ],
   "id": "b6483a8ff76eb1f7",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "IOPub data rate exceeded.\n",
      "The Jupyter server will temporarily stop sending output\n",
      "to the client in order to avoid crashing it.\n",
      "To change this limit, set the config variable\n",
      "`--ServerApp.iopub_data_rate_limit`.\n",
      "\n",
      "Current values:\n",
      "ServerApp.iopub_data_rate_limit=1000000.0 (bytes/sec)\n",
      "ServerApp.rate_limit_window=3.0 (secs)\n",
      "\n"
     ]
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:23.312679Z",
     "start_time": "2025-05-26T06:32:23.309579Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "briefed_md_file=briefed_md_file.absolute()\n",
    "integrated_dir=integrated_dir.absolute()\n",
    "# os.chdir(integrated_dir)\n",
    "# pypandoc.convert_file(\n",
    "#     briefed_md_file,\n",
    "#     'docx',\n",
    "#     outputfile=integrated_dir / \"mapper.docx\",\n",
    "# )"
   ],
   "id": "ea8a8191c42db9d7",
   "outputs": [],
   "execution_count": 16
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-26T06:32:23.326476Z",
     "start_time": "2025-05-26T06:32:23.324033Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# pypandoc.convert_file(\n",
    "#     integrated_dir / \"index.md\",\n",
    "#     'docx',\n",
    "#     outputfile=integrated_dir / \"index.docx\",\n",
    "#\n",
    "# )"
   ],
   "id": "e9a3fa7ec3359e5",
   "outputs": [],
   "execution_count": 17
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
